/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.classnet.db;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author karltinawi
 */
@Entity
@Table(name = "phone")
@NamedQueries({@NamedQuery(name = "Phone.findByUser", query = "SELECT p FROM Phone p WHERE p.phonePK.user = :user"), @NamedQuery(name = "Phone.findByCategory", query = "SELECT p FROM Phone p WHERE p.phonePK.category = :category"), @NamedQuery(name = "Phone.findByPhone", query = "SELECT p FROM Phone p WHERE p.phone = :phone")})
public class Phone implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected PhonePK phonePK;
    @Column(name = "phone")
    private String phone;
    @JoinColumn(name = "user", referencedColumnName = "email", insertable = false, updatable = false)
    @ManyToOne
    private User user1;

    public Phone() {
    }

    public Phone(PhonePK phonePK) {
        this.phonePK = phonePK;
    }

    public Phone(String user, String category) {
        this.phonePK = new PhonePK(user, category);
    }

    public PhonePK getPhonePK() {
        return phonePK;
    }

    public void setPhonePK(PhonePK phonePK) {
        this.phonePK = phonePK;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public User getUser1() {
        return user1;
    }

    public void setUser1(User user1) {
        this.user1 = user1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (phonePK != null ? phonePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Phone)) {
            return false;
        }
        Phone other = (Phone) object;
        if ((this.phonePK == null && other.phonePK != null) || (this.phonePK != null && !this.phonePK.equals(other.phonePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.classnet.db.Phone[phonePK=" + phonePK + "]";
    }

}
